#!/bin/bash

source /opt/common/common.sh

#修改注释的参数

#默认服务器IP
sshhost="SERVER_IP"
#默认用户名
sshuser="USERNAME"
#登录服务器别名
sshalias="ALIASNAME"
#配置文件储存的节名
section="site_date"

# 修改ID1/2 IP1/2 __SERVER_IP1/2 __USER1/2
#
# 使用$> login.sh ID1 
#　代表用__USER1用户自动登录__SERVER_IP1的服务器
#　密码自动提取
#  设置密码用setpasswd.sh

for i in $@
do
  if [ "$i" == "ID1" -o "$i" == "IP1" ]; then
    sshalias="ID1"
    sshhost="__SERVER_IP1"
    sshuser="__USER1"
  elif [ "$i" == "ID2" -o "$i" == "IP2" ]; then
    sshalias="ID2"
    sshhost="__SERVER_IP2"
    sshuser="__USER1"
  fi
done

sshini="$sshalias"_"$sshuser"
sshpass=`get_sproj_ini "$sshini" "$section"`

if [ ! -z "$sshpass" ]; then
  show t "登录服务器:$sshalias($sshhost)"
  sshpass -p $sshpass ssh $sshuser@$sshhost
else
  input_and_set_site_spwd "远程" "$sshalias"  "$sshuser" "$sshhost"
  sshpass=`get_sproj_ini "$sshini" "$section"`
  if [ ! -z "$sshpass" ]; then
    show t "登录服务器:$sshalias($sshhost)"
    sshpass -p $sshpass ssh $sshuser@$sshhost
  fi
fi

